package com.captainbank.tcl.tclapplication.ui.activity.function;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.captainbank.tcl.tclapplication.R;
import com.captainbank.tcl.tclapplication.ui.activity.basic.BaseActivity;
import com.captainbank.tcl.tclapplication.utils.MyToast;
import com.captainbank.tcl.tclapplication.utils.RSAUtils;
import com.captainbank.tcl.tclapplication.utils.StringUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by TCL on 2019/8/9.
 * Describe:
 */
public class RSATestActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.et)
    EditText et;
    @BindView(R.id.tv_show)
    TextView tvShow;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_rsa_test;
    }

    @Override
    protected void initView() {
        toolbar.setTitle(getString(R.string.title_rsa));
    }

    @Override
    protected void setListener() {
        tvShow.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                tvShow.setText("");
                return true;
            }
        });
    }

    @OnClick({R.id.btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn:
                String input = et.getText().toString().trim();
                try {
                    String show;
//                    String pKey = "MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgE5gW7ypyFTgP5smFu/P6VgfTXhuC4Xd/XlvFC2htc/ifcxgHSdCmqYo1mZLzBvyYWV0pU3IRgDdgGCpSuPqBD1U3MQ+bD3Gw+qemNvOislWdBl14q5JShYsOl8tB7evYQazRPg54XPtFA4RQcPSnmi8ZN993E263xJCd5HrmAOPAgMBAAE=";
                    if(StringUtil.checkIsNotNull(input)){
                        show = RSAUtils.encrypt(input,"");
                    }else{
                        input = "{\"username\":\"18121259693\",\"password\":\"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAMpO4X\"}";
                        show = RSAUtils.encrypt(input,"");
                    }
                    tvShow.setText(show);
                } catch (Exception e) {
                    e.printStackTrace();
                    MyToast.toastNormal(this,"解密异常");
                }
                break;
        }
    }
}
